package com.aruba.welcomeapplication;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    private ViewPager vp;
    private int[] layouts = {
            R.layout.welcome1,
            R.layout.welcome2,
            R.layout.welcome3
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        vp = findViewById(R.id.vp);
        WelcomeAdapter welcomeAdapter = new WelcomeAdapter(getSupportFragmentManager());
        vp.setAdapter(welcomeAdapter);

        WelcompagerTransformer transformer = new WelcompagerTransformer();
        vp.setPageTransformer(true, transformer);

        vp.setOnPageChangeListener(transformer);
    }

    class WelcomeAdapter extends FragmentPagerAdapter {

        public WelcomeAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int i) {
            TranslateFragment translateFragment = new TranslateFragment();
            Bundle bundle = new Bundle();
            bundle.putInt("layoutId", layouts[i]);
            bundle.putInt("pageIndex", i);
            translateFragment.setArguments(bundle);
            return translateFragment;
        }

        @Override
        public int getCount() {
            return 3;
        }
    }

}
